package com.hg.library.model;

import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.os.Parcel;
import android.os.Parcelable;

/**
 * Created by ASUS-PC on 2016/1/18.
 */
public class AppInfoModel implements Parcelable,Comparable<AppInfoModel> {

    /**
     * 应用标题
     */
    public String title;

    /**
     * 应用包名
     */
    public String appPkgName;

    /**
     * 应用uri
     */
    public String intentUri;

    /**
     * 安装时间
     */
    public long installTime;

    /**
     * 应用图标
     */
    public Bitmap bitmapLogo;

    /**
     * 应用版本号
     */
    public int versionCode;

    /**
     * 应用大小
     */
    public int fileLength;

    /**
     * 单位 M
     */
    public float fileSizeM;

    public Drawable drawable;

    public boolean isSystemApp;

    public String iconUrl;

    public String downloadUrl;

    public AppInfoModel() {
    }


    protected AppInfoModel(Parcel in) {
        title = in.readString();
        appPkgName = in.readString();
        intentUri = in.readString();
        installTime = in.readLong();
        bitmapLogo = in.readParcelable(Bitmap.class.getClassLoader());
        versionCode = in.readInt();
        fileLength = in.readInt();
        fileSizeM = in.readFloat();
        isSystemApp = in.readByte() != 0;
        iconUrl = in.readString();
        downloadUrl = in.readString();
    }

    public static final Creator<AppInfoModel> CREATOR = new Creator<AppInfoModel>() {
        @Override
        public AppInfoModel createFromParcel(Parcel in) {
            return new AppInfoModel(in);
        }

        @Override
        public AppInfoModel[] newArray(int size) {
            return new AppInfoModel[size];
        }
    };

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(title);
        dest.writeString(appPkgName);
        dest.writeString(intentUri);
        dest.writeLong(installTime);
        dest.writeParcelable(bitmapLogo, flags);
        dest.writeInt(versionCode);
        dest.writeInt(fileLength);
        dest.writeFloat(fileSizeM);
        dest.writeByte((byte) (isSystemApp ? 1 : 0));
        dest.writeString(iconUrl);
        dest.writeString(downloadUrl);
    }

    @Override
    public int compareTo(AppInfoModel another) {
        return new Long(installTime).compareTo(another.installTime);
    }

    @Override
    public boolean equals(Object o) {
        AppInfoModel model = (AppInfoModel) o;
        return appPkgName.equals(model.appPkgName);
    }

    @Override
    public String toString() {
        return "AppInfoModel{" +
                "title='" + title + '\'' +
                ", appPkgName='" + appPkgName + '\'' +
                ", intentUri='" + intentUri + '\'' +
                ", installTime=" + installTime +
                ", bitmapLogo=" + bitmapLogo +
                ", versionCode=" + versionCode +
                ", fileLength=" + fileLength +
                ", fileSizeM=" + fileSizeM +
                ", drawable=" + drawable +
                ", isSystemApp=" + isSystemApp +
                ", iconUrl=" + iconUrl +
                ", downloadUrl=" + downloadUrl +
                '}';
    }
}
